home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
Libraries
/
PlayerPRO 4.4.1
/
MADF Library 3.0
/
Game.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-10
|
7KB
|
325 lines
//
// Exemple d'utilisation des routines contenues
// dans la ROSSETMOD.lib et la ROSSETGraph.lib
//
// Copyright 1992 Antoine ROSSET
//
//
#include "Retrace.h"
#include "MAD.h"
#include "RDriver.h"
#include "Sound.h"
#include "AIFF.h"
#include "SoundInput.h"
extern Boolean Reading;
extern short PL;
extern long alphaTest = 0;
short SIter = 370;
Point PP ={ 200, 470}, De = { 200, 100};
Boolean ActualSize = false;
Ptr tempPtr;
Ptr Val;
void DoConversionS3M( Str255 fName, short vRef);
void MyDebugStr( Str255 aStr)
{
DebugStr( aStr);
}
unsigned char *pStrcat(unsigned char *s, unsigned char *t)
{
unsigned char *s2;
short tLen;
s2 = s + *s;
*s += (tLen = *t);
for (++tLen; --tLen; s2[tLen] = t[tLen]);
return (s);
}
Handle DoExp1to3( Handle sound, unsigned long numSampleFrames)
{
long i;
Ptr inState, outState;
Handle outBuffer;
outState = NewPtrClear( 128);
inState = NewPtrClear( 128);
if( inState == nil)
{
/* Error */
}
outBuffer = NewHandle( numSampleFrames*6);
if( outBuffer == nil)
{
/* Error */
}
HLock( sound);
HLock( outBuffer);
Exp1to3( *sound, *outBuffer, numSampleFrames, inState, outState, 1, 1);
HUnlock( sound);
HUnlock( outBuffer);
DisposHandle( sound);
sound = outBuffer;
DisposPtr( inState);
DisposPtr( outState);
return sound;
}
Handle DoExp1to6( Handle sound, unsigned long numSampleFrames)
{
long i;
Ptr inState, outState;
Handle outBuffer;
outState = NewPtrClear( 128);
inState = NewPtrClear( 128);
if( inState == nil)
{
/* Error */
}
outBuffer = NewHandle( numSampleFrames * 6);
if( outBuffer == nil)
{
/* Error */
}
HLock( sound);
HLock( outBuffer);
Exp1to6( *sound, *outBuffer, numSampleFrames, inState, outState, 1, 1);
HUnlock( sound);
HUnlock( outBuffer);
DisposHandle( sound);
sound = outBuffer;
DisposPtr( inState);
DisposPtr( outState);
return sound;
}
void ConvertInstrument( register Byte *tempPtr, register long sSize)
{
register Byte val = 0x80;
while( sSize > 0)
{
sSize--;
*(tempPtr + sSize) += val;
}
}
/*************************************************************/
/* SndToHandle */
/* This function is only useful if you use OSErr PlaySound() */
/*************************************************************/
/* This function extract a raw handle from a 'snd ' handle */
/*************************************************************/
Handle SndToHandle( Handle sound, short *sampleSize)
{
Ptr soundPtr;
short soundFormat;
short numSynths, numCmds, CompressID;
long offset, MusSize;
SoundHeaderPtr header;
CmpSoundHeader *CmpHeader;
ExtSoundHeader *ExtHeader;
SndCommand cmd;
OSErr result;
long i,x, numFrames;
Boolean change = false;
*sampleSize = 8;
HLock( sound);
soundPtr = *sound;
soundFormat = *(short*)soundPtr;
switch(soundFormat)
{
case 1:
numSynths = ((short*)soundPtr)[1];
numCmds = *(short*)(soundPtr+4+numSynths*6);
break;
case 2:
numSynths = 0;
numCmds = ((short*)soundPtr)[2];
break;
default:
MyDebugStr("\p SndToHandle");
break;
}
offset = 6 + 6*numSynths + 8*numCmds;
header = (SoundHeaderPtr) (StripAddress(*sound) + offset);
switch( header->encode)
{
case cmpSH:
CmpHeader = (CmpSoundHeader*) header;
CompressID = CmpHeader->compressionID;
*sampleSize = CmpHeader->sampleSize;
MusSize = (*CmpHeader).numFrames;
HLock( sound);
BlockMove( (*CmpHeader).sampleArea, *sound, MusSize);
HUnlock( sound);
switch( CompressID )
{
case threeToOne:
MusSize *= 2;
sound = DoExp1to3( sound, MusSize);
MusSize *= 3;
break;
case sixToOne:
sound = DoExp1to6( sound, MusSize);
MusSize *= 6;
break;
default:
break;
}
break;
case extSH:
ExtHeader = (ExtSoundHeader*) header;
MusSize = ExtHeader->numFrames;
*sampleSize = ExtHeader->sampleSize;
if( *sampleSize == 16) MusSize *= 2;
HLock( sound);
BlockMove( ExtHeader->sampleArea, *sound, MusSize);
HUnlock( sound);
break;
case stdSH:
MusSize = header->length;
BlockMove( (*header).sampleArea, *sound, MusSize);
HUnlock( sound);
break;
}
ConvertInstrument( (Byte*) *sound, MusSize);
HUnlock( sound);
SetHandleSize( sound, MusSize);
if( MemError()) DebugStr( "\p MemError in SetHandleSize");
return( sound);
}
main()
{
EventRecord theEvent;
Point where = { 50,50};
SFReply reply;
short srcFile, sampleSize;
OSErr iErr;
long musicSize;
DialogPtr TheDia;
Handle itemHandle;
Rect itemRect;
short itemType, i, itemHit;
Handle mySound[ 4]; // my 4 sound resource
/* Initialisation de la toolbox */
InitGraf( &qd.thePort);
InitFonts();
InitWindows();
TEInit();
InitMenus();
InitCursor();
MaxApplZone();
/******************************************/
/*** Load and prepare my sound resource ***/
/******************************************/
for( i = 0 ; i < 4; i++)
{
mySound[ i] = GetResource( 'snd ', 128 + i);
if( mySound[ i] != 0L) mySound[ 0] = SndToHandle( mySound[ i], &sampleSize); /* Convert the Snd Handle to raw handle */
HLock( mySound[ i]);
}
/******************************************/
/*** Initialize driver ***/
/******************************************/
PtrSystem = false;
if( RInitMusic( SMStereo, 4, false) != noErr) DebugStr("\pNeed more memory");
RLoadMusicRsrc( 'MADF', 3214);
RPlayMusic(); // Run the driver
/******************************************/
/*** Open my dialog ***/
/******************************************/
TheDia = GetNewDialog( 128,0L, (WindowPtr) -1L);
SetPort( TheDia);
do
{
ModalDialog( 0L, &itemHit);
switch( itemHit)
{
case 2:
Reading = !Reading;
CleanDriver();
break;
case 3:
RPlaySound( *mySound[ 0], GetHandleSize( mySound[ 0]), 0, 30, sampleSize, 0, 0); // On track ID 0, 30 = normal period
break;
case 4:
RPlaySound( *mySound[ 1], GetHandleSize( mySound[ 1]), 1, 30, sampleSize, 0, 0); // On track ID 1, 30 = normal period
break;
case 5:
RPlaySound( *mySound[ 2], GetHandleSize( mySound[ 2]), 2, 30, sampleSize, 0, 0); // On track ID 2, 30 = normal period
break;
case 6:
RPlaySound( *mySound[ 3], GetHandleSize( mySound[ 3]), 3, 30, sampleSize, 0, 0); // On track ID 3, 30 = normal period
break;
}
}while( itemHit != 1);
DisposDialog( TheDia);
RStopMusic(); // Stop the driver
RClearMusic(); // Clear music
RQuitMusic(); // Dispose driver
ExitToShell();
}